import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class LoginFrame extends JFrame {
    private JTextField username;
    private JPasswordField password;
    private JButton login,register;
    public LoginFrame() {
        super();
        this.setSize(300,200);
        this.setTitle("Login");
        this.setLocationRelativeTo(getOwner());//居中

        //设置组合布局———3行2列表格
        Container cont=getContentPane();
        cont.setLayout(new GridLayout(3,2));

        //添加“用户名”、“密码”
        cont.add(new JLabel("username"));
        username=new JTextField(10);
        cont.add(username);
        cont.add(new JLabel("password"));
        password =new JPasswordField(10);
        cont.add(password);

        //添加“登录”、“注册”按钮
        login=new JButton(new ImageIcon("C:\\Users\\周建荣\\Desktop\\查询.jpg"));
        register=new JButton (new ImageIcon("C:\\Users\\周建荣\\Desktop\\添加.jpg"));
        cont.add(login);
        cont.add(register);

        //注册监听器
        login.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                String pass =new String(password.getPassword());
                if(username.getText().equals("ding")&&pass.equals("123456")) {
                    Demo hello=new Demo();
                    hello.setVisible(true);
                    dispose();
                } else {
                    JOptionPane.showMessageDialog(null, "你输入的密码没有通过验证");
                }
            }
        });
    }
    public static void main(String[] args) {
        LoginFrame w = new LoginFrame();
        w.setVisible(true);
    }
}
